﻿using MySqlTool;
using ParkSaleSDK.Adapter;
using ParkSaleSDK.QuickTool;
using System;

namespace ParkSaleSDK
{
    namespace Data
    {


        [Serializable]
        public class TraitInfo
        {
            private int trait = 0;
            private string[] traitnames = { "地下", "光线充足", "靠近路边", "特价", "公开销售", "临近商店" };
            private bool[] traitswitch;
            public TraitInfo()
            {
                traitswitch = new bool[traitnames.Length];
            }
            public static implicit operator TraitInfo(int i)
            {
                return TraitInfo.IntToTriat(i);
            }
            public static explicit operator int(TraitInfo trait)
            {
                return TraitInfo.TraitToInt(trait);
            }
            public static TraitInfo IntToTriat(int t)
            {
                TraitInfo trait = new TraitInfo();
                int i = trait.traitswitch.Length - 1;
                while (t > 0 && i >= 0)
                {

                    if (t % 2 == 1)
                    {
                        trait.traitswitch[i] = true;
                    }
                    t = t >> 1;
                    i--;

                }
                return trait;
            }
            public static int TraitToInt(TraitInfo trait)
            {
                int t = 1, r = 0;
                for (int i = trait.traitswitch.Length-1; i >=0 ; i--)
                {
                    if (trait.traitswitch[i] == true)
                    {
                        r += t;
                    }
                    t = t << 1;
                }
                return r;
            }

            public bool IsUnderGround
            {
                get => traitswitch[0];
                set => traitswitch[0] = value;
            }
            public bool IsFullLight
            {
                get => traitswitch[1];
                set => traitswitch[1] = value;
            }
            public bool IsNearRoad
            {
                get => traitswitch[2];
                set => traitswitch[2] = value;
            }
            public bool IsSpecialForSale
            {
                get => traitswitch[3];
                set => traitswitch[3] = value;
            }
            public bool IsOpenForSale
            {
                get => traitswitch[4];
                set => traitswitch[4] = value;
            }
            public bool IsNearShop
            {
                get => traitswitch[5];
                set => traitswitch[5] = value;
            }

        }

        [Serializable]
        public class OutOrder
        {
            public Order Basic
            {
                get;
                set;
            }
            public Location LocationInfo
            {
                get;
                set;
            }
            public Company CompanyInfo
            {
                get;
                set;
            }
        }
        public class Su
        {
            [MysqlProperty("token")]
            public string Token
            {
                get;
                set;
            }
        }

        [Serializable]
        public class PublicMessage
        {
            public int ID
            {
                get;
                set;
            }
            public String Time
            {
                get;
                set;
            }
            public string Content
            {
                get;
                set;
            }
            public string From
            {
                get;
                set;
            }
            public int Handled
            {
                get;
                set;
            }
            public string To
            {
                get;
                set;
            }
        }
        [Serializable]
        public class FullMessage : PublicMessage
        {
            public string Type
            {
                get;
                set;
            }

            public string Arg
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 调研功能结果数据类
        /// </summary>
        [System.Serializable]
        public class SurveyData
        {
            ParkSaleSDK.Modularity.ISurvey survey;

            public string Name
            {
                get => survey.Name();
            }
            public string About
            {
                get => survey.About();
            }

            public bool RequsetStatus
            {
                get;
                set;
            }
            public object Result
            {
                get;
                set;
            }
            public SurveyData()
            {

            }
            public SurveyData(Modularity.ISurvey survey)
            {
                this.survey = survey;
            }

        }
        public class MessageData
        {
            [MysqlProperty(c_Message.k_time)]
            public DateTime Time
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_id)]
            public int ID
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_type)]
            public string Type
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_to)]
            public string To
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_from)]
            public string From
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_content)]
            public string Content
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_handled)]
            public int Handled
            {
                get;
                set;
            }
            [MysqlProperty(c_Message.k_arg)]
            public string Arg
            {
                get;
                set;
            }
            public FullMessage ToFullMessage()
            {
                return new FullMessage() { ID = this.ID, Content = Content, From = From, To = To, Time = Helper.TimeTOString(Time), Type = Type, Handled = this.Handled, Arg = Arg };
            }
            public PublicMessage ToPublicMessage()
            {
                return ToFullMessage();
            }

        }

        /// <summary>
        /// 车位数据库数据
        /// </summary>
        [System.Serializable]
        public class Park
        {
            [MysqlProperty(c_Parking.k_Trait)]
            public int Trait
            {
                get;
                set;
            }

            /// <summary>
            /// 车位编号
            /// </summary>
            [MysqlProperty(c_Parking.k_ID)]
            public int ID { get; set; }
            /// <summary>
            /// 车位所在小区编号
            /// </summary>
            [MysqlProperty(c_Parking.k_Location)]
            public int Location { get; set; }
            /// <summary>
            /// 车位售价
            /// </summary>
            [MysqlProperty(c_Parking.k_Price)]
            public double Price { get; set; }
            /// <summary>
            /// 车位号
            /// </summary>
            [MysqlProperty(c_Parking.k_Number)]
            public int Number { get; set; }
            /// <summary>
            /// 车位状态
            /// </summary>
            [MysqlProperty(c_Parking.k_Status)]
            public int Status { get; set; }
            /// <summary>
            /// 车位备注
            /// </summary>
            [MysqlProperty(c_Parking.k_Note)]
            public string Note { get; set; }
        }
        /// <summary>
        /// 优惠数据库数据
        /// </summary>
        [System.Serializable]
        public class UserDiscount
        {
            /// <summary>
            /// 优惠券编号
            /// </summary>
            [MysqlProperty(c_Discount.k_ID)]
            public int ID { get; set; }
            /// <summary>
            /// 优惠方法代号
            /// </summary>
            [MysqlProperty(c_Discount.k_Code)]
            public string Code { get; set; }
            /// <summary>
            /// 优惠券归属人ID
            /// </summary>
            [MysqlProperty(c_Discount.k_Belong)]
            public string Belong { get; set; }
            /// <summary>
            /// 优惠券使用订单
            /// </summary>
            [MysqlProperty(c_Discount.k_Order)]
            public int? Order { get; set; }
            /// <summary>
            /// 优惠券领取时间
            /// </summary>
            [MysqlProperty(c_Discount.k_PickTime)]
            public string PickTime { get; set; }
            /// <summary>
            /// 优惠券参数
            /// </summary>
            [MysqlProperty(c_Discount.k_Arg)]
            public string Arg { get; set; }

        }
        /// <summary>
        /// 订单数据库数据
        /// </summary>
        [System.Serializable]
        public class Order
        {
            /// <summary>
            /// 订单编号
            /// </summary>
            [MysqlProperty(c_Order.k_id)]
            public int ID { get; set; }
            /// <summary>
            /// 车位所在小区编号
            /// </summary>
            [MysqlProperty(c_Order.k_Address)]
            public int Address { get; set; }
            /// <summary>
            /// 订购者id
            /// </summary>
            [MysqlProperty(c_Order.k_Belong)]
            public string Belong { get; set; }

            /// <summary>
            /// 车位编号
            /// </summary>
            [MysqlProperty(c_Order.k_Number)]
            public int Number { get; set; }
            /// <summary>
            /// 订单生成时间
            /// </summary>
            [MysqlProperty(c_Order.k_Time)]
            public string Time { get; set; }
            /// <summary>
            /// 订单状态
            /// </summary>
            [MysqlProperty(c_Order.k_Status)]
            public int Status { get; set; }
            /// <summary>
            /// 销售者
            /// </summary>
            [MysqlProperty(c_Order.k_Seller)]
            public int Seller { get; set; }
            /// <summary>
            /// 成交价
            /// </summary>
            [MysqlProperty(c_Order.k_Price)]
            public double Price { get; set; }
        }
        /// <summary>
        /// 小区数据库数据
        /// </summary>
        [System.Serializable]
        public class Location
        {
            /// <summary>
            /// 小区ID
            /// </summary>
            [MysqlProperty(c_Location.k_id)]
            public int ID { get; set; }
            /// <summary>
            /// 小区详细地址
            /// </summary>
            [MysqlProperty(c_Location.k_Address)]
            public string Address { get; set; }
            /// <summary>
            /// 小区开发商id
            /// </summary>
            [MysqlProperty(c_Location.k_Belong)]
            public int Belong { get; set; }
            /// <summary>
            /// 小区名
            /// </summary>
            [MysqlProperty(c_Location.k_Name)]
            public string Name { get; set; }

            [MysqlProperty(c_Location.k_longitude)]
            public double Longitude { get; set; }
            [MysqlProperty(c_Location.k_latitude)]
            public double Latitude { get; set; }
        }
        /// <summary>
        /// 公司数据库数据
        /// </summary>
        [System.Serializable]
        public class Company
        {
            /// <summary>
            /// 公司编号
            /// </summary>
            [MysqlProperty(c_Company.k_id)]
            public int ID { get; set; }
            /// <summary>
            /// 公司简介
            /// </summary>
            [MysqlProperty(c_Company.k_About)]
            public string About { get; set; }
            /// <summary>
            /// 公司类型
            /// </summary>
            [MysqlProperty(c_Company.k_Type)]
            public int Type { get; set; }
            /// <summary>
            /// 公司名
            /// </summary>
            [MysqlProperty(c_Company.k_Name)]
            public string Name { get; set; }
            /// <summary>
            /// 公司联系电话
            /// </summary>
            [MysqlProperty(c_Company.k_Phone)]
            public string Phone { get; set; }
            /// <summary>
            /// 公司邮箱
            /// </summary>
            [MysqlProperty(c_Company.k_Email)]
            public string Email { get; set; }
        }
        /// <summary>
        /// 广告数据库数据
        /// </summary>
        [System.Serializable]
        public class Advertisement
        {
            /// <summary>
            /// 广告编号
            /// </summary>
            [MysqlProperty(c_Advertisement.k_id)]
            public int ID { get; set; }
            /// <summary>
            /// 广告图存放位置
            /// </summary>
            [MysqlProperty(c_Advertisement.k_Image)]
            public string Image { get; set; }
            /// <summary>
            /// 广告标题
            /// </summary>
            [MysqlProperty(c_Advertisement.k_Title)]
            public string Title { get; set; }
            /// <summary>
            /// 广告引导链接
            /// </summary>
            [MysqlProperty(c_Advertisement.k_Url)]
            public string Url { get; set; }
            /// <summary>
            /// 广告投放公司id
            /// </summary>
            [MysqlProperty(c_Advertisement.k_Belong)]
            public int Belong { get; set; }
        }

        /// <summary>
        /// 产权数据库数据
        /// </summary>
        [System.Serializable]
        public class Rights
        {
            /// <summary>
            /// 产权号
            /// </summary>
            [MysqlProperty(c_Rights.k_ID)]
            public int ID
            {
                get;
                set;
            }
            /// <summary>
            /// 产权对象，车位id
            /// </summary>
            [MysqlProperty(c_Rights.k_Item)]
            public int Item
            {
                get;
                set;
            }
            /// <summary>
            /// 产权归属者id
            /// </summary>
            [MysqlProperty(c_Rights.k_Belong)]
            public string Belong
            {
                get;
                set;
            }
            public override string ToString()
            {
                return $"{ID} Belong:{Belong}  Item:{Item}";
            }
        }
        [System.Serializable]
        public class OwnedHouse
        {
            [MysqlProperty(c_OwnedHouse.k_id)]
            public int ID
            {
                get;
                set;
            }
            [MysqlProperty(c_OwnedHouse.k_owner)]
            public string Owner
            {
                get;
                set;
            }
            /// <summary>
            /// 用户所在小区号
            /// </summary>
            [MysqlProperty(c_OwnedHouse.k_location)]
            public int Location
            {
                get;
                set;
            }
            /// <summary>
            /// 用户所在楼号
            /// </summary>
            [MysqlProperty(c_OwnedHouse.k_house)]
            public int House
            {
                get;
                set;
            }
            /// <summary>
            /// 用户门牌号
            /// </summary>
            [MysqlProperty(c_OwnedHouse.k_number)]
            public int Number
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 用户数据库数据
        /// </summary>

        public class User:safe_User
        {
            /// <summary>
            /// 用户密码
            /// </summary>
            [MysqlProperty(c_User.k_Password)]
            public string Password
            {
                get;
                set;
            }
        }

        /// <summary>
        /// 安全用户信息
        /// </summary>
        [System.Serializable]
        public class safe_User
        {
            [MysqlProperty(c_User.k_Like)]
            public int Like
            {
                get;
                set;
            }

            /// <summary>
            /// 用户身份证号
            /// </summary>
            [MysqlProperty(c_User.k_ID)]
            public string ID
            {
                get;
                set;
            }
            /// <summary>
            /// 用户名
            /// </summary>
            [MysqlProperty(c_User.k_UserName)]
            public string UserName
            {
                get;
                set;
            }
            /// <summary>
            /// 用户手机号
            /// </summary>
            [MysqlProperty(c_User.k_Phone)]
            public string Phone
            {
                get;
                set;
            }
        }
    }
}